@include('admin::layouts.header')
<link rel="stylesheet" href="{!! config('admin.admin_url')!!}/plugins/zTree/css/zTreeStyle.css" type="text/css">
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field">
        <legend>配置规则</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane">
                <ul id="treeDemo" class="ztree"></ul>
                @include('admin::layouts.submit',['url'=>route('admin.auth_group.index')])
            </form>
        </div>
    </fieldset>
</div>
@include('admin::layouts.footer')
<script type="text/javascript" src="{!! config('admin.admin_url') !!}/common/js/jquery.2.1.1.min.js"></script>
<script type="text/javascript" src="{!! config('admin.admin_url') !!}/plugins/zTree/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="{!! config('admin.admin_url') !!}/plugins/zTree/js/jquery.ztree.excheck.min.js"></script>
<script type="text/javascript">
    var setting = {
        check:{enable: true},
        view: {showLine: false, showIcon: false, dblClickExpand: false},
        data: {
           simpleData: {enable: true, pIdKey:'pid', idKey:'id'},
           key:{name:'title'}
        }
    };	var zNodes = {!! $data !!};      	
    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.setting.check.chkboxType = { "Y":"ps", "N":"ps"};
    }
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    setCheck();
    layui.use(['form', 'layer'], function () {
        var form = layui.form, layer = layui.layer;
        form.on('submit(submit)', function () {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            // 提交到方法 默认为本身
            var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
                nodes=treeObj.getCheckedNodes(true),
                v="";
            for(var i=0;i<nodes.length;i++){
                v+=nodes[i].id + "|";
            }
            $.post("{{route('admin.auth_group.access_update',['id'=>$id])}}", {_method: 'PUT','rules':v}, function (res) {
                layer.close(loading);				if(res.status == 1){                    layer.msg(res.msg,{icon: 1, time: 1000},function(){                        location.href = res.url;                    });                }else{                    layer.msg(res.error,{icon: 2, time: 1000});                }
            });
        })
    });
</script>